<?php
namespace app\admin\controller\expenses;

use app\common\controller\Backend;

/**
 * Created by PhpStorm.
 * FileName: Index.php
 * User: Administrator
 * Date: 2017/11/01
 * Time: 13:42
 */

class Verify extends Backend {

    protected $model = null;
    protected $communityModel = null;
    protected $projectModel = null;
    protected $houseModel = null;
    protected $payModel = null;
    //检索时匹配的字段
    protected $searchfields = null;
    protected $noNeedRight = ['selectpage','get_project_by_cm_code'];

    public function _initialize() {
        parent::_initialize();
        $this->model = model('Expenses');
        $this->communityModel = model('Community');
        $this->projectModel = model('ExpensesProject');
        $this->houseModel = model('House');
        $this->payModel = model('ExpensesPay');
        $this->view->assign('community',$this->communityModel->where(array('code'=>array('in',parent::getCommunityIdByAuth())))->field('code,name')->select());
        $this->view->assign('pay',$this->payModel->field('code,name')->select());
    }

    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax())
        {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('pkey_name'))
            {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->where($where)
                ->order($sort, $order)
                ->count();

            $list = $this->model
                ->where($where)
                ->with('community,project,house,pay')
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }

    public function verify_one($ids = null) {
        return parent::modify($ids,'verify_one');
    }

    public function verify_batch($ids = null) {
        $list = $this->model->whereIn('id',$ids)->select();
        $this->assign('list',$list);
        return parent::modify($ids,'verify_batch');
    }
}